import { createRouter, createWebHistory, createWebHashHistory } from 'vue-router';
import { uesUserStore } from '@/stores/user';

const router = createRouter({
    history: createWebHistory(import.meta.env.VITE_BASE_PATH),
    // history: createWebHashHistory(),
    routes: [
        {
            path: '/',
            component: () => import('@/layout/Layout.vue'),
            redirect: '/flow',
            children: [
                {
                    path: "/flow",
                    component: () => import('@/views/flow/index.vue'),
                    redirect: '/flow/calendar',
                    children: [
                        {
                            path: "/flow/calendar",
                            component: () => import('@/views/flow/calendar.vue'),
                        },
                        {
                            path: "/flow/fillinfo",
                            component: () => import('@/views/flow/fillinfo.vue'),
                        },
                        {
                            path: "/flow/confirminfo",
                            component: () => import('@/views/flow/confirminfo.vue'),
                        },
                        {
                            path: "/flow/complete",
                            component: () => import('@/views/flow/complete.vue'),
                        }
                    ]
                },
                {
                    path: "/record",
                    component: () => import('@/views/record/index.vue'),
                },
                {
                    path: "/record/:id",
                    component: () => import('@/views/record/detail.vue'),
                }
            ]
        }
    ],
});

router.beforeEach((to, from, next) => {
    if (to.query.token) {
        uesUserStore().setToken(to.query.token);
    }
    next();
})

export default router;
